/**
 * @Author: YU
 * @Date: 2021-10-23 22:11:47
 * @LastEditTime: 2021-10-25 20:13:46
 * @LastEditors: YU
 * @Description: Vuex
 */
import Vue from 'vue'
import Vuex from 'vuex'
import { getItem, setItem, removeItem } from '@/utils/storage'

Vue.use(Vuex)

const TOKEN = 'TOKEN'
const ACTIVEPATH = 'ACTIVEPATH'
export default new Vuex.Store({
  state: {
    token: getItem(TOKEN),
    activePath: getItem(ACTIVEPATH)
  },
  mutations: {
    setUser(state, token) {
      state.token = token
      setItem(TOKEN, token)
    },
    setActivePath(state, activePath) {
      state.activePath = activePath
      setItem(ACTIVEPATH, activePath)
    },
    removeUser(state) {
      state.token = null
      removeItem(TOKEN)
    }
  },
  actions: {},
  modules: {}
})
